//
// Created by Administrator on 2021/6/1.
//
#include <vector>
#include <iostream>

using namespace std;

class Solution {
public:
    vector<bool> canEat(vector<int> &candiesCount, vector<vector<int>> &queries) {
        vector<long long> preSum(candiesCount.size() + 1, 0); // 前缀和
        // 每天只吃一颗 最晚可以在 前缀和-1天吃到糖果   最前面有个0
        for (int i = 1; i < preSum.size(); ++i) {
            preSum[i] = preSum[i - 1] + candiesCount[i - 1];
        }
        vector<bool> ans(queries.size(), false);
        // 最早什么时候能吃到和每天允许的上限有关
        for (int i = 0; i < queries.size(); ++i) {
            long long latest = preSum[queries[i][0] + 1] - 1; // 最晚能吃到的日子
            long long  earliest = preSum[queries[i][0]] / queries[i][2]; // 最早能吃到的日子
            if (queries[i][1] <= latest and queries[i][1] >= earliest) ans[i] = true;
        }
        return ans;
    }
};

int main() {
    vector<int> candiesCount{7, 4, 5, 3, 8};
    vector<vector<int>> query{{0, 2,  2},
                              {4, 2,  4},
                              {2, 13, 1000000}};
    Solution sol;
    auto ans = sol.canEat(candiesCount, query);
    for (auto x:ans) cout << x << endl;
    return 0;
}